package org.zpmis.api.http;

import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.zpmis.api.business.StatisticsWebService;
import org.zpmis.common.base.BaseController;
import org.zpmis.common.exception.BusinessException;
import org.zpmis.common.result.PlatformResult;
import org.zpmis.domain.project.qo.StatisticsQo;

import javax.annotation.Resource;

@RestController
@RequestMapping("/statistics")
@Slf4j
public class StatisticsController extends BaseController {

    @Resource
    private StatisticsWebService statisticsWebService;


    /**
     * 项目人员工时统计
     * @param statisticsQo
     * @return
     */
    @PostMapping("/projectUserHoursStatistics")
    public PlatformResult projectUserHoursStatistics(@Validated @RequestBody StatisticsQo statisticsQo){
        try {
            return PlatformResult.success(statisticsWebService.projectUserHoursStatistics(statisticsQo));
        } catch (BusinessException e) {
            log.error("[StatisticsController]---projectUserHoursStatistics--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[StatisticsController]---projectUserHoursStatistics--->Exception:",e);
            return PlatformResult.failure();
        }
    }
}
